import sys
import os
import networkx as nx
from params import *
import pylab as plt

datasets = ['bkite','fsquare','gowalla']
lbls = ['Brightkite', 'Foursquare', 'Gowalla']
node_dist = [5651.0,8494.0,5663.0]
link_dist = [2041.0,1442.0,1792.0]
degs = [7.88,22.07,9.48,7.0]
#datasets.append('placefriends2')
#lbls.append('Gowalla (PF)')
plots = []
for dataset,avg_deg in zip(datasets,degs):
    file = os.path.join(WORKDIR, 'gsn','traces',dataset,'%s_graph.txt'%dataset)
    file = os.path.join(WORKDIR, 'gsn','results',dataset,'%s_degree_distribution.txt'%dataset)
    x = []
    x2 = []
    y = []
    c = []
    acc = 0
    for line in open(file):
        a,b = map(int,line.strip().split(';'))
        a = float(a)
        a2 = a/avg_deg
        x.append(a)
        x2.append(a2)
        y.append(b)
        acc += b
        c.append(acc)

    tot = c[-1]
    c = [1-1.0*i/tot for i in c]
    plots.append((x,x2,c))

plt.figure()
plt.clf()
plt.axes(FIG_AXES2)
for (x,x2,c),m in zip(plots,markers):
    plt.loglog(x,c,'k%s'%m, mfc='None')
plt.legend(lbls,
        loc='upper right',
        columnspacing=5,
        numpoints=1)
plt.grid(True)
plt.xlabel('Degree')
plt.ylabel('CCDF')
plt.xlim(xmax=1e4)


inset_width = 0.4
inset_height = 0.3 #inset_width*golden_mean

a = plt.axes([0.22,0.25,inset_width,inset_height])
for (x,x2,c),m in zip(plots,markers):
    plt.loglog(x2,c,'k%s'%m, mfc='None', ms=1)
a.grid(True)
plt.setp(a,xticks=[],yticks=[])
plt.savefig('three_degree_distributions_inset.pdf')
plt.close()

plt.figure()
plt.clf()
plt.axes(FIG_AXES2)
for (x,x2,c),m in zip(plots,markers):
    plt.loglog(x,c,'k%s'%m, mfc='None')
plt.legend(lbls,
        loc='lower left',
        columnspacing=5,
        numpoints=1)
plt.grid(True)
plt.xlabel('Degree')
plt.ylabel('CCDF')
plt.xlim(xmax=1e4)
plt.savefig('three_degree_distributions.pdf')
plt.close()

plt.figure()
plt.clf()
plt.axes(FIG_AXES2)
for (x,x2,c),m in zip(plots,markers):
    plt.loglog(x2,c,'k%s'%m, mfc='None')
plt.legend(lbls,
        loc='lower left',
        columnspacing=5,
        numpoints=1)
plt.grid(True)
plt.xlabel('Degree')
plt.ylabel('CCDF')
plt.xlim(xmax=1e3)
plt.savefig('three_degree_distributions_scaled.pdf')
plt.close()

